Prise en charge du mode.
[minwii.git] / WiiMouse2IR coeff0.1.PIE
1 Wiimote1.led1 = true
2 Wiimote2.led1 = true
3 Wiimote2.led4 = true
4 Wiimote3.led2 = true
5 Wiimote4.led2 = true
6 Wiimote4.led4 = true
7 Wiimote5.led3 = true
8 Wiimote6.led3 = true
9 Wiimote6.led4 = true
10 //Mouse Control Script using IR
11 //by vkapadia with much assistance from inio
12 //vkapadia@vkapadia.com
13 //
14 //Calibration:
15 //To calibrate, run this program and put the Wiimote on a flat surface face-up.
16 //Then read the values in the debug line (next to the run button).
17 //Change these values until the debug line reads approx. all zeros.
18 var.xtrim1 = -1
19 var.ytrim1 = -25
20 var.ztrim1 = 2
21
22 var.xtrim2 = 2
23 var.ytrim2 = -30
24 var.ztrim2 = 2
25
26 var.coeff = 0.1
27
28 //
29 //Options:
30 var.deadzone = 5 //distance in pixels that you have to move the wiimote in
31 //order for it to register movement. Creates a "dead zone" around the pointer
32 //to make it easier to click. Higher = smoother but less accurate.
33 //fake cursor init
34
35 //cursor2.visible = true
36
37 //more options to be added later
38
39 //Controls:
40 //Point Wiimote = Move Mouse
41 //D-Pad = Arrow Keys
42 //B-Button = Left Click
43 //Home = Middle Click
44 //A-Button = Right Click
45 //Plus and Minus = Control Volume
46 //One = Unmapped
47 //Two = Unmapped
48 //
49 //If the pointer hits the edge of the screen, the Wiimote will rumble a bit.
50 //
51 //The LEDs attempt to emulate KITT's grill from Knight Rider
52
53 //WIIMOTE 1
54 //***Do not edit anything below this line unless you know what you are doing.***
55 var.accx1 = wiimote1.RawForceX + var.xtrim1
56 var.accy1 = wiimote1.RawForceY + var.ytrim1
57 var.accz1 = wiimote1.RawForceZ + var.ztrim1
58
59 if wiimote1.dot1vis and wiimote1.dot2vis then
60
61 if var.accy1 > -7 then
62 var.orientation1 = 0
63 elseif var.accy1 > -45 then
64 if var.accx1 < 0 then
65 var.orientation1 = 3
66 else
67 var.orientation1 = 1
68 endif
69 else
70 var.orientation1 = 2
71 endif
72
73 if var.leftpoint1 = 0 then
74 if var.orientation1 = 0 then
75 if wiimote1.dot1x < wiimote1.dot2x then
76 var.leftpoint1 = 1
77 else
78 var.leftpoint1 = 2
79 endif
80 endif
81 if var.orientation1 = 1 then
82 if wiimote1.dot1y > wiimote1.dot2y then
83 var.leftpoint1 = 1
84 else
85 var.leftpoint1 = 2
86 endif
87 endif
88 if var.orientation1 = 2 then
89 if wiimote1.dot1x > wiimote1.dot2x then
90 var.leftpoint1 = 1
91 else
92 var.leftpoint1 = 2
93 endif
94 endif
95 if var.orientation = 3 then
96 if wiimote1.dot1y < wiimote1.dot2y then
97 var.leftpoint1 = 1
98 else
99 var.leftpoint1 = 2
100 endif
101 endif
102 endif
103
104 if var.leftpoint1 = 1 then
105 var.fix1x1 = wiimote1.dot1x
106 var.fix1y1 = wiimote1.dot1y
107 var.fix2x1 = wiimote1.dot2x
108 var.fix2y1 = wiimote1.dot2y
109 else
110 var.fix1x1 = wiimote1.dot2x
111 var.fix1y1 = wiimote1.dot2y
112 var.fix2x1 = wiimote1.dot1x
113 var.fix2y1 = wiimote1.dot1y
114 endif
115
116 var.dx1 = var.fix2x1 - var.fix1x1
117 var.dy1 = var.fix2y1 - var.fix1y1
118 var.cx1 = (var.fix1x1+var.fix2x1)/1024.0 - 1
119 var.cy1 = (var.fix1y1+var.fix2y1)/1024.0 - .75
120
121 var.d1 = sqrt(var.dx1*var.dx1+var.dy1*var.dy1)
122
123 var.dx1 = var.dx1 / var.d1
124 var.dy1 = var.dy1 / var.d1
125
126 var.ox1 = -var.dy1*var.cy1-var.dx1*var.cx1;
127 var.oy1 = -var.dx1*var.cy1+var.dy1*var.cx1;
128
129 var.ax1 = (var.ox1 * var.coeff*screen.desktopwidth) + (screen.desktopwidth* var.coeff / 2)
130 var.ay1 = (-var.oy1* var.coeff * screen.desktopwidth) + (screen.desktopheight* var.coeff / 2)
131
132 var.dx1 = var.ax1 - cursor2.posx
133 var.dy1 = var.ay1 - cursor2.posy
134
135 var.d1 = sqrt((var.dx1*var.dx1)+(var.dy1*var.dy1))
136
137 var.a1 = 180 / (200 + var.d1 * var.d1 * var.d1 * .001)
138
139 if var.d1 <= var.deadzone then var.a1 = 1
140
141 //debug = var.d + " " + var.a
142
143 var.finalx1 = cursor2.posx * var.a1 + var.ax1 * (1 - var.a1)
144 var.finaly1 = cursor2.posy * var.a1 + var.ay1 * (1 - var.a1)
145
146
147 cursor2.posx = smooth(var.finalx1,3,5)
148 cursor2.posy = smooth(var.finaly1,3,5)
149
150 else
151
152 var.leftpoint1 = 0
153
154 endif
155
156 var.xpos1 = var.finalx1
157 var.ypos1 = var.finaly1
158 ppjoy1.analog0 = ensuremaprange(var.xpos1,0,screen.desktopwidth* var.coeff,-1,1)
159 ppjoy1.analog1 = ensuremaprange(var.ypos1,0,screen.desktopheight* var.coeff,-1,1)
160
161 if wiimote1.B or wiimote1.A or wiimote1.Up or wiimote1.down or wiimote1.Left or wiimote1.Right == true
162 ppjoy1.digital0 = true
163 else
164 ppjoy1.digital0 = false
165 endif
166
167 //WIIMOTE 2
168 //***Do not edit anything below this line unless you know what you are doing.***
169 var.accx2 = wiimote2.RawForceX + var.xtrim2
170 var.accy2 = wiimote2.RawForceY + var.ytrim2
171 var.accz2 = wiimote2.RawForceZ + var.ztrim2
172
173 if wiimote2.dot1vis and wiimote2.dot2vis then
174
175 if var.accy2 > -7 then
176 var.orientation2 = 0
177 elseif var.accy2 > -45 then
178 if var.accx2 < 0 then
179 var.orientation2 = 3
180 else
181 var.orientation2 = 1
182 endif
183 else
184 var.orientation2 = 2
185 endif
186
187 if var.leftpoint2 = 0 then
188 if var.orientation2 = 0 then
189 if wiimote2.dot1x < wiimote2.dot2x then
190 var.leftpoint2 = 1
191 else
192 var.leftpoint2 = 2
193 endif
194 endif
195 if var.orientation2 = 1 then
196 if wiimote2.dot1y > wiimote2.dot2y then
197 var.leftpoint2 = 1
198 else
199 var.leftpoint2 = 2
200 endif
201 endif
202 if var.orientation2 = 2 then
203 if wiimote2.dot1x > wiimote2.dot2x then
204 var.leftpoint2 = 1
205 else
206 var.leftpoint2 = 2
207 endif
208 endif
209 if var.orientation = 3 then
210 if wiimote2.dot1y < wiimote2.dot2y then
211 var.leftpoint2 = 1
212 else
213 var.leftpoint2 = 2
214 endif
215 endif
216 endif
217
218 if var.leftpoint2 = 1 then
219 var.fix1x2 = wiimote2.dot1x
220 var.fix1y2 = wiimote2.dot1y
221 var.fix2x2 = wiimote2.dot2x
222 var.fix2y2 = wiimote2.dot2y
223 else
224 var.fix1x2 = wiimote2.dot2x
225 var.fix1y2 = wiimote2.dot2y
226 var.fix2x2 = wiimote2.dot1x
227 var.fix2y2 = wiimote2.dot1y
228 endif
229
230 var.dx2 = var.fix2x2 - var.fix1x2
231 var.dy2 = var.fix2y2 - var.fix1y2
232 var.cx2 = (var.fix1x2+var.fix2x2)/1024.0 - 1
233 var.cy2 = (var.fix1y2+var.fix2y2)/1024.0 - .75
234
235 var.d2 = sqrt(var.dx2*var.dx2+var.dy2*var.dy2)
236
237 var.dx2 = var.dx2 / var.d2
238 var.dy2 = var.dy2 / var.d2
239
240 var.ox2 = -var.dy2*var.cy2-var.dx2*var.cx2;
241 var.oy2 = -var.dx2*var.cy2+var.dy2*var.cx2;
242
243 var.ax2 = (var.ox2 * var.coeff*screen.desktopwidth) + (screen.desktopwidth* var.coeff / 2)
244 var.ay2 = (-var.oy2* var.coeff * screen.desktopwidth) + (screen.desktopheight* var.coeff / 2)
245
246 var.dx2 = var.ax2 - cursor3.posx
247 var.dy2 = var.ay2 - cursor3.posy
248
249 var.d2 = sqrt((var.dx2*var.dx2)+(var.dy2*var.dy2))
250
251 var.a2 = 180 / (200 + var.d2 * var.d2 * var.d2 * .001)
252
253 if var.d2 <= var.deadzone then var.a2 = 1
254
255 //debug = var.d + " " + var.a
256
257 var.finalx2 = cursor3.posx * var.a2 + var.ax2 * (1 - var.a2)
258 var.finaly2 = cursor3.posy * var.a2 + var.ay2 * (1 - var.a2)
259
260
261 cursor3.posx = smooth(var.finalx2,3,5)
262 cursor3.posy = smooth(var.finaly2,3,5)
263
264 else
265
266 var.leftpoint2 = 0
267
268 endif
269
270 var.xpos2 = var.finalx2
271 var.ypos2 = var.finaly2
272 ppjoy2.analog0 = ensuremaprange(var.xpos2,0,screen.desktopwidth* var.coeff,-1,1)
273 ppjoy2.analog1 = ensuremaprange(var.ypos2,0,screen.desktopheight* var.coeff,-1,1)
274
275 if wiimote2.B or wiimote2.A or wiimote2.Up or wiimote2.down or wiimote2.Left or wiimote2.Right == true
276 ppjoy2.digital0 = true
277 else
278 ppjoy2.digital0 = false
279 endif
280
281 debug = var.accx2+ " " + var.accy2+ " " + var.accz2